public class Solution953 {
    public boolean isAlienSorted(String[] words, String order) {
        for (int i=0;i<words.length-1;i++){
            String a=null,b=null;
            for (int j=0;j<Math.min(words[i].length(),words[i+1].length());j++){
                if (words[i].charAt(j)!=words[i+1].charAt(j)){
                    a=String.valueOf(words[i].charAt(j));
                    b=String.valueOf(words[i+1].charAt(j));
                    break;
                }
            }
            if (a==null){
                if (words[i].length()>words[i+1].length()){
                    return false;
                }
            }else{
                int x=order.indexOf(a);
                int y=order.indexOf(b);
                if (x!=-1 && y!=-1 && x>y){
                    return false;
                }
            }
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(new Solution953().isAlienSorted(new String[]{"apple","app"},"hlabcdefgijkmnopqrstuvwxyz"));
    }
}


